package com.peng.leetcode.greedy;

/**
 * NumWaterBottles
 *
 * @author: lupeng6
 * @create: 2021/2/1 18:44
 */
public class NumWaterBottles {

    public static void main(String[] args) {
        int numBottles = 15, numExchange =4;
        System.out.println(new NumWaterBottles().numWaterBottles(numBottles, numExchange));
    }

    public int numWaterBottles(int numBottles, int numExchange) {
        int ans = numBottles;
        int num = numBottles;
        while (num >= numExchange) {
            ans += num / numExchange;
            if (num % numExchange == 0) {
                num = num / numExchange;
            } else {
                num = (num / numExchange) + (num % numExchange);
            }
        }
        return ans;
    }
}
